package com.yidian.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yidian.pojo.seckill.SeckillGoods;
import com.yidian.server.seckill.SeckillGoodsService;
import com.yidian.util.DateUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author whb
 * @create 2021-10-08 13:34
 * @desciption 秒杀商品控制类
 */
@CrossOrigin
@RestController
@RequestMapping(value = "seckill/goods")
public class SeckillControl {
    @Reference
    private SeckillGoodsService seckillGoodsService;

    /**
     * 测试控制类方法
     * @return
     */
    @GetMapping("/returnName")
    public String returnName(){
        return "Seckill goods.";
    }

    /**
     * 获取秒杀时间段列表
     * @return
     */
    @RequestMapping("/dateMenus")
    public List<Date> dateMenus(){
        return DateUtil.getDateMenus();
    }

    /**
     * 根据时间获取秒杀商品
     * @param time
     * @return
     */
    @GetMapping("/list")
    public List<SeckillGoods> list(String time){
        return seckillGoodsService.list(time);
    }

    /**
     * 查询秒杀商品
     * @param time
     * @param id
     * @return
     */
    @GetMapping("/queryGoods")
    public SeckillGoods queryGoods(String time,Long id){
        return seckillGoodsService.queryGood(time,id);
    }
}
